package com.cn.springcloudwechat.service.personalcenter.serviceImpl;

import com.cn.springcloudwechat.common.utils.DateUtils;
import com.cn.springcloudwechat.common.utils.TimeUtil;
import com.cn.springcloudwechat.mapper.mapper.weixin.user.WxFollowerDao;
import com.cn.springcloudwechat.model.weixin.user.Follower;
import com.cn.springcloudwechat.model.weixin.user.WxFollower;
import com.cn.springcloudwechat.service.personalcenter.service.WxFollowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service("WxFollower")
public class WxFollowerServiceImpl implements WxFollowerService {

    
    @Autowired
    WxFollowerDao wxFollowerDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer insert(WxFollower record) {
        return wxFollowerDao.insertWxFollower(record);
    }

    @Override
    public WxFollower castWxFollower(Follower follower) {
        WxFollower wxFollower = new WxFollower();
        wxFollower.setCity(follower.getCity());
        wxFollower.setCountry(follower.getCountry());
        wxFollower.setGroupid(String.valueOf(follower.getGroupid()));
        wxFollower.setHeadimgurl(follower.getHeadimgurl());
        wxFollower.setLanguage(follower.getLanguage());
        wxFollower.setNickname(follower.getNickname());
        wxFollower.setOpenid(follower.getOpenid());
        wxFollower.setProvince(follower.getProvince());
        wxFollower.setRemark(follower.getRemark());
        wxFollower.setSex(follower.getSex());
        wxFollower.setSubscribe(follower.getSubscribe());
        wxFollower.setSubscribeTime(DateUtils.formatTime(follower.getSubscribeTime()));
        wxFollower.setUnionid(follower.getUnionid());
        return wxFollower;
    }

    @Override
    public WxFollower getWxFollower(String openId) {
        return wxFollowerDao.getWxFollower(openId);
    }
}
